var pages;
(function (pages) {
    var Section = (function () {
        function Section(element, menuitem) {
            this.element = element;
            this.menuitem = menuitem;
        }
        Section.prototype.show = function () {
            this.menuitem.addClass('active');
            this.element.fadeIn();
        };
        Section.prototype.hide = function (callback) {
            this.menuitem.removeClass('active');
            this.element.fadeOut(callback);
        };
        return Section;
    })();
    pages.Section = Section;    
    var Options = (function () {
        function Options() {
        }
        Options.prototype.save = function () {
            core.Settings.instance.project = $('#projectTitle').val();
            core.Settings.instance.css = this.cssEditor.getSession().getValue();
            core.Settings.instance.template = this.templateEditor.getSession().getValue();
            core.Settings.instance.itemfunction = this.functionEditor.getSession().getValue();
        };
        Options.prototype.load = function () {
            $('#projectTitle').val(core.Settings.instance.project);
            this.cssEditor.getSession().setValue(core.Settings.instance.css);
            this.templateEditor.getSession().setValue(core.Settings.instance.template);
            this.functionEditor.getSession().setValue(core.Settings.instance.itemfunction);
        };
        Options.prototype.initialize = function () {
            var _this = this;
            var sections = $('.sections section');
            var menu = $('.navigator ul');
            sections.each(function (i, e) {
                var sectionElm = $(e);
                var title = sectionElm.attr('title');
                var menuItem = $('<a href="javascript:void()">' + title + '</a>');
                var section = new Section(sectionElm, menuItem);
                menu.append($('<li></li>').append(menuItem));
                if(_this.currentsection == null) {
                    _this.currentsection = section;
                    section.show();
                } else {
                    section.element.hide();
                }
                menuItem.click(function () {
                    if(section != _this.currentsection) {
                        _this.currentsection.menuitem.removeClass('active');
                        section.menuitem.addClass('active');
                        _this.currentsection.element.fadeOut(function () {
                            section.element.fadeIn();
                        });
                        _this.currentsection = section;
                    }
                });
            });
            this.cssEditor = ace.edit("cssEditor");
            this.cssEditor.setTheme("ace/theme/chrome");
            this.cssEditor.getSession().setMode("ace/mode/css");
            this.templateEditor = ace.edit("templateEditor");
            this.templateEditor.setTheme("ace/theme/chrome");
            this.templateEditor.getSession().setMode("ace/mode/html");
            this.functionEditor = ace.edit("itemfunction");
            this.functionEditor.setTheme("ace/theme/chrome");
            this.functionEditor.getSession().setMode("ace/mode/javascript");
            this.load();
            $('#save').click(function () {
                _this.save();
            });
            $('#cancel').click(function () {
                _this.load();
            });
            $('#reset').click(function () {
                core.Settings.instance.clear();
                _this.load();
            });
            $('.editorwrap').resize(function () {
                _this.cssEditor.resize();
                _this.templateEditor.resize();
                _this.functionEditor.resize();
            });
        };
        return Options;
    })();
    pages.Options = Options;    
})(pages || (pages = {}));

